package com.example.demo.mapper;

import com.example.demo.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface CourseMapper {
    @Select("select * from course where status = 1")
    List<Course> findAlllCourse();

    @Select("select * from course where 1=1 and coursename=#{coursename} and status = 1")
    List<Course> findCourseByCoursename(String coursename);

    @Select("select * from course where 1=1 and teachername=#{teachername} and status = 1")
    List<Course> findCourseByTeachername(String teachername);

    @Select("select 1 from course where type = #{type} limit 1")
    Boolean selectCourseByCourseType(int type);

    @Delete("update from course set status = 2 where courseid=#{courseid}")
    int deleteCou(int courseid);

    @Insert("insert into course(courseid,id,teachername,coursename,gredit,term,begintime,endtime) values (#{courseid},#{id},#{teachername},#{coursename},#{gredit},#{term},#{begintime},#{endtime})")
    int insertCou(Course course);

    @Select("select * from course where courseid=#{courseid}")
    Course selectCourseById(int courseid);

    @Select("select * from course where id=#{id}")
    Course selectCourseByIds(int id);

    @Update("update course set id=#{id},teachername=#{teachername},coursename=#{coursename},gredit=#{gredit},term=#{term},begintime=#{begintime},endtime=#{endtime} where courseid=#{courseid}")
    int updateCou(String teachername, String coursename,Float gredit, String term, Date begintime, int courseid, int id, Date endtime);
}
